import sys
import codecs

class ParseFile:
    
    #parsing KR_Kvutza file
        file = open('C:\\Documents and Settings\\User\\Desktop\\data_dumps\\KR_Kvutza.txt', 'r')
        K_COURSE_NUMs = []
        K_KVUTZA_NUMs = []
        K_KVUTZA_SEM_YEARs = []
        MISHKALs = []
        COURSE_NAMEs = []
        FACULTY_NAMEs = []
        HUG_NAMEs = []
        KVUTZA_TYPEs = []
        OFEN_HORAAs = []
        HAVURAs = []
        COURSE_LANGUAGEs = []
        MATALOTs = []
        MATCONET_KVUTZAs = []
        VIDEOs = []
        for n, line in enumerate(file.readlines()):
                K_COURSE_NUM, K_KVUTZA_NUM, K_KVUTZA_SEM_YEAR, MISHKAL, COURSE_NAME, FACULTY_NAME, HUG_NAME, KVUTZA_TYPE, OFEN_HORAA, HAVURA, COURSE_LANGUAGE, MATALOT, MATCONET_KVUTZA, VIDEO_temp = line.split('~')
                VIDEO_temp2 = VIDEO_temp.split('\n')
                if(n!=0):
                        K_COURSE_NUMs.append(K_COURSE_NUM)
                        K_KVUTZA_NUMs.append(K_KVUTZA_NUM)
                        K_KVUTZA_SEM_YEARs.append(K_KVUTZA_SEM_YEAR)
                        MISHKALs.append(MISHKAL)
                        COURSE_NAMEs.append(COURSE_NAME)
                        FACULTY_NAMEs.append(FACULTY_NAME)
                        HUG_NAMEs.append(HUG_NAME)
                        KVUTZA_TYPEs.append(KVUTZA_TYPE)
                        OFEN_HORAAs.append(OFEN_HORAA)
                        HAVURAs.append(HAVURA)
                        COURSE_LANGUAGEs.append(COURSE_LANGUAGE)
                        MATALOTs.append(MATALOT)
                        MATCONET_KVUTZAs.append(MATCONET_KVUTZA)
                        VIDEOs.append(VIDEO_temp2[0])
        #print(VIDEOs)
        file.close()
        
    #maps 4 num prefix of a course num to faculty and hug       
        faculty_hug_dict = {}
        i = 0
        for course_num in K_COURSE_NUMs:
                prefix = course_num[0:4]
                if(not (faculty_hug_dict.has_key(prefix))):
                        faculty_hug_dict[prefix] = [FACULTY_NAMEs[i],HUG_NAMEs[i]]
                i=i+1      
                           
    #parsing KR_Kvutza_Moed file    
        file = open('C:\\Documents and Settings\\User\\Desktop\\data_dumps\\KR_Kvutza_Moed.txt', 'r')
        K_COURSE_NUMs2 = []
        K_KVUTZA_NUMs2 = []
        K_KVUTZA_SEM_YEARs2 = []
        K_MOEDs = []
        K_MOED_TYPEs = []
        ME_SHAAs = []
        AD_SHAAs = []
        MOED_DATEs = []
        for n2, line2 in enumerate(file.readlines()):
                K_COURSE_NUM2, K_KVUTZA_NUM2, K_KVUTZA_SEM_YEAR2, K_MOED, K_MOED_TYPE, ME_SHAA, AD_SHAA, MOED_DATE_temp = line2.split('~')
                MOED_DATE_temp2 = MOED_DATE_temp.split('\n')
                if(n2!=0):
                        K_COURSE_NUMs2.append(K_COURSE_NUM2)
                        K_KVUTZA_NUMs2.append(K_KVUTZA_NUM2)
                        K_KVUTZA_SEM_YEARs2.append(K_KVUTZA_SEM_YEAR2)
                        K_MOEDs.append(K_MOED)
                        K_MOED_TYPEs.append(K_MOED_TYPE)
                        ME_SHAAs.append(ME_SHAA)
                        AD_SHAAs.append(AD_SHAA)
                        MOED_DATEs.append(MOED_DATE_temp2[0])
        #print(MOED_DATEs)
        file.close()
        
    #parsing KR_Kvutza_Zamak file
        file = open('C:\\Documents and Settings\\User\\Desktop\\data_dumps\\KR_Kvutza_Zamak.txt', 'r')
        K_COURSE_NUMs3 = []
        K_KVUTZA_NUMs3 = []
        K_KVUTZA_SEM_YEARs3 = []
        YOMs = []
        ME_SHAAs = []
        AD_SHAAs = []
        LECTURE_NAMEs = []
        BINYANs = []
        CHEDERs = []
        for n3, line3 in enumerate(file.readlines()):
                K_COURSE_NUM3, K_KVUTZA_NUM3, K_KVUTZA_SEM_YEAR3, YOM, ME_SHAA, AD_SHAA, LECTURE_NAME, BINYAN, CHEDER_temp = line3.split('~')
                CHEDER_temp2 = CHEDER_temp.split('\n')
                CHEDER_temp3 = CHEDER_temp2[0].split(' ')
                if(n3!=0):
                        K_COURSE_NUMs3.append(K_COURSE_NUM3)
                        K_KVUTZA_NUMs3.append(K_KVUTZA_NUM3)
                        K_KVUTZA_SEM_YEARs3.append(K_KVUTZA_SEM_YEAR3)
                        YOMs.append(YOM)
                        ME_SHAAs.append(ME_SHAA)
                        AD_SHAAs.append(AD_SHAA)
                        LECTURE_NAMEs.append(LECTURE_NAME)
                        BINYANs.append(BINYAN)
                        CHEDERs.append(CHEDER_temp3[0])
        #print(CHEDERs)
        file.close()
        
    #parsing BD_Stats file
        file = open('C:\\Documents and Settings\\User\\Desktop\\data_dumps\\BD_Stats.txt', 'r')
        K_FACBIDDs = []
        K_COURSE_NUMs4 = []
        K_KVUTZA_NUMs4 = []
        K_KVUTZA_SEM_YEARs4 = []
        PLACESs = []
        REQUESTEDs = []
        ACCEPTEDs = []
        REJECTEDs = []
        REJECTED_NETOs = []
        MAX_POINTSs = []
        MIN_ACCEPT_POINTSs = []
        for n4, line4 in enumerate(file.readlines()):
                K_FACBIDD, K_COURSE_NUM4, K_KVUTZA_NUM4, K_KVUTZA_SEM_YEAR4, PLACES, REQUESTED, ACCEPTED, REJECTED, REJECTED_NETO, MAX_POINTS, MIN_ACCEPT_POINTS_temp = line4.split('~')
                MIN_ACCEPT_POINTS_temp2 = MIN_ACCEPT_POINTS_temp.split('\n')
                if(n4!=0):
                        K_FACBIDDs.append(K_FACBIDD)
                        K_COURSE_NUMs4.append(K_COURSE_NUM4)
                        K_KVUTZA_NUMs4.append(K_KVUTZA_NUM4)
                        K_KVUTZA_SEM_YEARs4.append(K_KVUTZA_SEM_YEAR4)
                        PLACESs.append(PLACES)
                        REQUESTEDs.append(REQUESTED)
                        ACCEPTEDs.append(ACCEPTED)
                        REJECTEDs.append(REJECTED)
                        REJECTED_NETOs.append(REJECTED_NETO)
                        MAX_POINTSs.append(MAX_POINTS)
                        MIN_ACCEPT_POINTSs.append(MIN_ACCEPT_POINTS_temp2[0])
        #print(MIN_ACCEPT_POINTSs)
        file.close()